<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <input type="text" v-focus.bg="color" />
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
    <script>
      //自定义指令
      //允许对底层dom进行操作

      //拥有三哥钩子函数
      //bind、inserted、update
      Vue.directive("focus", {
        bind(el, binding) {
          //第一次绑定到节点的时候触发
          console.log(el.parentNode);
        },
        inserted(el, binding) {
          //el就是u指令所在的dom元素
          //binding指令描述的对象
          //第一次插入父节点时候触发
          console.log(el);
          el.focus();
          el.style.color = binding.value;
          let bgColor = !!binding.modifiers['bg'];
          // console.log(bgColor)
          if(bgColor){
            alert("只因为你太美")
          }
        },
        update(el, binding) {
          //更新的时候触发
          console.log(el.parentNode);
          el.style.color = binding.value;
          // let bgColor = !!binding.modifiers.bg;
          // console.log(bgC)
        },
      });
      const vm = new Vue({
        el: "#app",
        data: {
          color:"red"
        },
        methods: {},
      });
    </script>
  </body>
</html>
